// CSE 142, Winter 2008, Marty Stepp // // This program randomly rolls two 6-sided dice until // it rolls a lucky 7. // // This version is modified to use a do/while loop. import java.util.*; public class Dice2 { public static void main(String[] args) { Random randy = new Random(); int count = 0; // how many times we have rolled int sum; do { // roll the dice int d1 = randy.nextInt(6) + 1; int d2 = randy.nextInt(6) + 1; sum = d1 + d2; System.out.println(d1 + " + " + d2 + " = " + sum); count++; } while (sum != 7); System.out.println("You won after " + count + " tries!"); } }